package com.ocr.utils.impl;

import com.baidu.aip.ocr.AipOcr;
import com.ocr.utils.IOcrUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author 化粪池堵塞的凶手
 */
@Service("ocrUtil")
public class OcrUtilsImpl implements IOcrUtils {

    @Autowired
    private AipOcr client;

    @Override
    public void openClient() {
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
    }

    @Override
    public String getOcr(String path) {
        // 调用接口
        JSONObject res = client.basicGeneral(path, new HashMap<String, String>());
        return res.toString(2);
    }
}
